﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;
namespace TestDxfDocument
{
    class ISYC_303_F34a
    {
        public static void ISYC_303_34a_H(Dictionary<string, Object> data) //整体桶式立铣刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double OAL = 75.75;
            double LPR = 48.04;
            double LU = 41.38;
            double DCONMS = 18.89;
            double LS = 31.54;
            double APMX = 12.53;
            double DN = 9.57;
            double LB = 37.77;
            double CPRADZ_1 = 4.59;
            double CPRADZ_2 = 7.68;
            double CPRADX_1 = 1.24;
            double CPRADX_2 = 4.13;
            double DCX = 17.05;
            double scale = OAL / 75.75;//放大系数

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //轮廓
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + OAL, v1.Y);
            Vector2 v3 = new Vector2(v1.X, v1.Y + DCONMS / 2.0 - 1 * scale);
            Vector2 v4 = fun.Inters(v3, fun.Polar(v3, 45 * pi / 180, OAL), fun.Polar(v1, 90 * pi / 180, DCONMS / 2.0), new Vector2(v1.X + OAL, v1.Y + DCONMS / 2.0));
            Vector2 v5 = new Vector2(v1.X + LS, v4.Y);
            Vector2 v6 = fun.Polar(v5, -33 * pi / 180, (DCONMS - DN) / 2.0 / Math.Sin(33 * pi / 180));
            Vector2 v7 = new Vector2(v6.X + (22.89 / 37.77) * LB, v6.Y);
            Vector2 v8 = new Vector2(v3.X, -v3.Y);
            Vector2 v9 = new Vector2(v4.X, -v4.Y);
            Vector2 v10 = new Vector2(v5.X, -v5.Y);
            Vector2 v11 = new Vector2(v6.X, -v6.Y);
            Vector2 v12 = new Vector2(v7.X, -v7.Y);
            Vector2 v13 = new Vector2(v2.X - LPR, v2.Y);
            Vector2 v14 = fun.Polar(v7, 132 * pi / 180, (4.61 / 9.57) * DN);
            Vector2 v15 = new Vector2(v14.X + (20.01 / 37.77) * LB, v14.Y);
            Vector2 v16 = new Vector2(v15.X, -v15.Y);
            Vector2 v17 = new Vector2(v14.X, -v14.Y);
            Vector2 v18 = fun.Polar(v12, 5 * pi / 180, (7.23 / 12.53) * APMX);
            Vector2 v19 = fun.Polar(v12, 19 * pi / 180, (10.88 / 12.53) * APMX);
            Vector2 v20 = fun.getPointForArcandLine(v12, fun.Polar(v12, -24 * pi / 180, OAL), fun.Polar(v12, 59 * pi / 180, (10.37 / 12.53) * APMX), new Arc(fun.Polar(v12, 59 * pi / 180, (10.37 / 12.53) * APMX), (10.37 / 12.53) * APMX, 0, 360));
            Vector2 v21 = fun.getPointForArcandLine(v18, fun.Polar(v18, 100 * pi / 180, OAL), fun.Polar(v12, 7 * pi / 180, (5.4 / 12.53) * APMX), new Arc(fun.Polar(v12, 7 * pi / 180, (5.4 / 12.53) * APMX), (10.37 / 12.53) * APMX, 0, 360));
            Vector2 v21_1 = fun.getPointForArcandLine(v19, fun.Polar(v19, 50 * pi / 180, OAL), fun.Polar(v12, 7 * pi / 180, (5.4 / 12.53) * APMX), new Arc(fun.Polar(v12, 7 * pi / 180, (5.4 / 12.53) * APMX), (10.37 / 12.53) * APMX, 0, 360));
            Vector2 v22 = new Vector2(v13.X - (4.19 / 31.54) * LS, v5.Y - (1.28 / 9.57) * DN);
            Vector2 v23 = new Vector2(v22.X + (3.3 / 31.54) * LS, v22.Y);
            Vector2 v24 = fun.Inters(v23, fun.Polar(v23, -45 * pi / 180, OAL), v13, fun.Polar(v13, 90 * pi / 180, OAL));
            Vector2 v25 = new Vector2(v22.X, -v22.Y);
            Vector2 v26 = new Vector2(v23.X, -v23.Y);
            Vector2 v27 = new Vector2(v24.X, -v24.Y);
            Vector2 v25_1 = fun.Polar(v5, -33 * pi / 180, fun.CalDistance(v5, v6) * 0.4);

            //第二部分
            Vector2 v28 = fun.Polar(v1, -71 * pi / 180, (57.88 / 17.89) * DCONMS);
            Vector2 v29 = new Vector2(v28.X + (32.79 / 37.77) * LB, v28.Y);
            Vector2 v30 = new Vector2(v28.X, v28.Y + (6.55 / 9.57) * DN);
            Vector2 v31 = new Vector2(v28.X + (12.65 / 37.77) * LB, v28.Y + (6.55 / 9.57) * DN);
            Vector2 v32 = fun.mirrorpoint(v31, v28, v29);
            Vector2 v33 = fun.mirrorpoint(v30, v28, v29);


            //作图部分-----------------------------------------------------------------------
            //第一部分
            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));
            polyline1.Vertexes.Add(new LwPolylineVertex(v4));//0
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));//1
            polyline1.Vertexes.Add(new LwPolylineVertex(v6));//2
            polyline1.Vertexes.Add(new LwPolylineVertex(v7));//3
            polyline1.Vertexes.Add(new LwPolylineVertex(v2));//4
            polyline1.Vertexes.Add(new LwPolylineVertex(v12));//5
            polyline1.Vertexes.Add(new LwPolylineVertex(v11));//6
            polyline1.Vertexes.Add(new LwPolylineVertex(v10));//7
            polyline1.Vertexes.Add(new LwPolylineVertex(v9));//8
            polyline1.Vertexes.Add(new LwPolylineVertex(v8));//9
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));//10
            polyline1.Vertexes[4].Bulge = Math.Tan(-98 * pi / 180 / 4);
            polyline1.Vertexes[5].Bulge = Math.Tan(-98 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline1, 0.3, contour);

            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v4));
            polyline2.Vertexes.Add(new LwPolylineVertex(v9));
            fun.PolyFill(dxf, polyline2, 0.3, contour);

            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v5));
            polyline3.Vertexes.Add(new LwPolylineVertex(v10));
            fun.PolyFill(dxf, polyline3, 0.3, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v6));
            polyline4.Vertexes.Add(new LwPolylineVertex(v11));
            fun.PolyFill(dxf, polyline4, 0.3, contour);

            //虚线
            LwPolyline polyline5 = new LwPolyline();
            polyline5.Vertexes.Add(new LwPolylineVertex(v22));
            polyline5.Vertexes.Add(new LwPolylineVertex(v23));
            polyline5.Vertexes.Add(new LwPolylineVertex(v24));
            polyline5.Vertexes.Add(new LwPolylineVertex(v27));
            polyline5.Vertexes.Add(new LwPolylineVertex(v26));
            polyline5.Vertexes.Add(new LwPolylineVertex(v25));
            polyline5.Layer = refin;
            polyline5.LinetypeScale = 5;
            polyline5.Linetype = Linetype.Dashed;
            dxf.AddEntity(polyline5);

            LwPolyline polyline6 = new LwPolyline();
            polyline6.Vertexes.Add(new LwPolylineVertex(v14));
            polyline6.Vertexes.Add(new LwPolylineVertex(v15));
            polyline6.Vertexes.Add(new LwPolylineVertex(v16));
            polyline6.Vertexes.Add(new LwPolylineVertex(v17));
            polyline6.Vertexes.Add(new LwPolylineVertex(v14));
            polyline6.Layer = refin;
            polyline6.LinetypeScale = 5;
            polyline6.Linetype = Linetype.Dashed;
            dxf.AddEntity(polyline6);

            //第二部分
            //轮廓
            LwPolyline polyline7 = new LwPolyline();
            polyline7.Vertexes.Add(new LwPolylineVertex(v30));
            polyline7.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, polyline7, 0.3, contour);

            LwPolyline polyline8 = new LwPolyline();
            polyline8.Vertexes.Add(new LwPolylineVertex(v33));
            polyline8.Vertexes.Add(new LwPolylineVertex(v32));
            fun.PolyFill(dxf, polyline8, 0.3, contour);

            var arc1 = fun.DrawArc4(v29, (14.26 / 17.05) * DCX, v31, 0);
            fun.drawBArc(dxf, arc1, 0.3, contour);

            var arc2 = fun.DrawArc4(v32, (14.26 / 17.05) * DCX, v29, 0);
            fun.drawBArc(dxf, arc2, 0.3, contour);

            Vector2 center1 = new Vector2(arc1.Center.X, arc1.Center.Y);
            Vector2 center2 = new Vector2(arc2.Center.X, arc2.Center.Y);

            Vector2 v34 = fun.Polar(center1, 90 * pi / 180, (14.26 / 17.05) * DCX);
            Vector2 v35 = fun.Polar(center2, -90 * pi / 180, (14.26 / 17.05) * DCX);
            Vector2 v36 = new Vector2(v29.X, v35.Y);
            Vector2 v37 = new Vector2(v36.X, v36.Y - DCX / 2.0);


            //标注---------------------------------------------------------------------------
            double height = 2 * scale;
            double arrowsize = 1 * scale;
            double exline = 0.5 * scale;

            //坐标系
            fun.Axis(dxf, v1, 180, 270, "", "", "PCS", 0.5 * scale, height, 0);
            fun.Axis(dxf, v13, 180, 270, "", "", "MCS", 0.5 * scale, height, 0);
            fun.Axis(dxf, v2, 180, 270, "", "", "CIP", 0.5 * scale, height, 0);
            fun.Axis(dxf, fun.Polar(v9, -126 * pi / 180, (10.93 / 17.89) / DCONMS), 180, 270, "Z", "X", "Y", 0.5 * scale, height, 0);
            fun.Axis(dxf, v29, 180, 270, "", "", "CIP", 0.6 * scale, height, 0);

            //DCONMS
            fun.dimrot1(dxf, v4, v9, 90, LS * 0.4, 0.1, height, arrowsize, exline, "DCONMS", "", "");

            //OAL
            fun.dimrot1(dxf, v3, v2, 0, DCONMS * 2, 0.1, height, arrowsize, exline, "OAL,LF", "", "");

            //LPR
            fun.dimrot1(dxf, v23, v2, 0, DCONMS * 1.6, 0.1, height, arrowsize, exline, "LPR,LTA", "", "");

            //LU
            fun.dimrot1(dxf, v25_1, v2, 0, DCONMS * 1.2, 0.1, height, arrowsize, exline, "LU", "", "");

            //CPRADZ_2
            fun.dimrot1(dxf, v18, v2, 0, DCONMS * 1.2, 0.1, height, arrowsize, exline, "CPRADZ_2", "", "");

            //APMX
            fun.dimrot1(dxf, v20, v2, 180, DCONMS * 0.6, 0.1, height, arrowsize, exline, "APMX", "", "");

            //CPRADZ_1
            fun.dimrot1(dxf, v19, v2, 180, DCONMS, 0.1, height, arrowsize, exline, "CPRADZ_1", "", "");

            //LB
            fun.dimrot1(dxf, v11, v2, 180, DCONMS * 1.2, 0.1, height, arrowsize, exline, "CPRADZ_1", "", "");

            //LS
            fun.dimrot1(dxf, v8, v10, 180, DCONMS * 0.4, 0.1, height, arrowsize, exline, "LS", "", "");

            //DN
            fun.dimrot1(dxf, v6, v11, -90, APMX * 0.5, 0.1, height, arrowsize, exline, "DN", "", "");

            //CPRADX_1
            fun.dimrot1(dxf, v19, v2, -90, APMX, 0.1, height, arrowsize, exline, "CPRADX_1", "", "");

            //CPRADX_2
            fun.dimrot1(dxf, v18, v2, -90, APMX * 1.5, 0.1, height, arrowsize, exline, "CPRADX_2", "", "");

            //DCX
            fun.dimrot1(dxf, v34, v36, -90, APMX * 2, 0.1, height, arrowsize, exline, "DCX", "", "");

            //CRP
            Circle circle1 = new Circle(v36, 1);
            circle1.Layer = dimensioning;
            dxf.AddEntity(circle1);

            fun.text1(dxf, fun.Polar(v36, -45 * pi / 180, 5), 90, "CRP");


            //箭头标注
            //CCMS
            fun.jt1(dxf, v24, 125, (8.63 / 17.89) * DCONMS, 1, "CCMS", height);

            //PRDRAD_2
            fun.jt1(dxf, v21, 115, (8.63 / 17.89) * DCONMS, 1, "PRDRAD_2", height);

            //LF
            Line line1 = new Line(v29, v37);
            line1.Layer = dimensioning;
            dxf.AddEntity(line1);

            fun.jt1(dxf, v37, 180, (8.63 / 17.89) * DCONMS, 1, "LF", height);

            //PRDRAD_1
            //fun.jt1(dxf, v21_1, 45, (8.63 / 17.89) * DCONMS, 1, "PRDRAD_1", height);

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
